package com.wink_172.activity

import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.databinding.DataBindingUtil
import com.wink_172.commons.R
import com.wink_172.commons.databinding.ActivitySelectorImageBinding
import com.wink_172.library.activity.SmartActivity
import com.wink_172.library.model.Constants
import com.wink_172.library.model.json.ImageData
import com.wink_172.library.utils.FileUtil
import com.wink_172.library.view.SelectorMultiImage
import java.util.*

/**
 * 选择多图实例
 */
class SelectorMultiImageActivity : SmartActivity() {
    lateinit var binding: ActivitySelectorImageBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this, R.layout.activity_selector_image)

        setStatusBarLightMode()
        initView()
        init()
    }

    private fun init() {
        (binding!!.selected3.selectContainerKotlin as SelectorMultiImage).init(this,0,
                object :
        com.wink_172.library.callback.ICallback {
        override fun onSendEvent(event: Int,vararg args: Any?) {//这个callback用的非常巧妙

        }
    })
    }

    private fun initView() {}
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode != RESULT_OK) {
            return
        }
        val uri: Uri?
        val url: String
        when (requestCode) {
            Constants.ACTIVITY_REQUEST_CODE_IMAGE_SEL -> {
                uri = data!!.data
                url = FileUtil.getRealFilePath(this, uri!!)
                //              x.image().bind(binding.imageTest, url);
                val images: MutableList<ImageData> = ArrayList()
                val imageData = ImageData()
                imageData.local_url = url
                images.add(imageData)
                (binding!!.selected3.selectContainerKotlin as SelectorMultiImage).bindImageList(images, false)
            }
            Constants.ACTIVITY_REQUEST_CODE_IMAGE_PHOTO -> {
                url = Constants.CropPath + (binding!!.selected3.selectContainerKotlin as SelectorMultiImage).photoName
                ////             x.image().bind((ImageView) binding.imageTest, url);
                val images: MutableList<ImageData> = ArrayList()
                val imageData = ImageData()
                imageData.local_url = url
                images.add(imageData)
                (binding!!.selected3.selectContainerKotlin as SelectorMultiImage).bindImageList(images, false)
            }
        }
    }

    companion object {
        fun startActivity(context: Context, vararg args: Any?) {
            val intent = Intent(context, SelectorMultiImageActivity::class.java)

            //intent.putExtra(Constants.PARAM_DATA1, (String) args[0]);
            context.startActivity(intent)
        }
    }
}